package com.idp.biz.bpuser.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.druid.util.StringUtils;
import com.common.model.PageModel;
import com.common.utils.ResourceUtil;
import com.github.pagehelper.PageHelper;
import com.idp.biz.bpuser.dao.BpUserDao;
import com.idp.biz.bpuser.entity.BpUser;
import com.idp.biz.bpuser.service.BpUserService;

/**
 * 用户管理service实现类
 * 
 * @author Stone 2019-06-29
 *
 */
@Service("bpUserService")
public class BpUserServiceImpl implements BpUserService {

	@Autowired
	private BpUserDao bpUserDao;
	
	@Override
	public PageModel<BpUser> findByPage(BpUser bpUser, PageModel<BpUser> page) {
		PageHelper.offsetPage(page.getStart(), page.getLength());
		page.initData(bpUserDao.findByPage(bpUser));
		return page;
	}
	
	@Override
	public List<BpUser> findBySearch(BpUser bpUser) {
		return bpUserDao.find(bpUser);
	}
	
	@Override
	public BpUser getById(String id) {
		return bpUserDao.getById(id);
	}
	
	@Override
	public BpUser getByToken(String token) {
		return bpUserDao.getByToken(token);
	}

	@Override
	public void add(BpUser bpUser) {
		if(StringUtils.isEmpty(bpUser.getId())){
			bpUser.setId(ResourceUtil.getUUID());
		}
		bpUserDao.add(bpUser);
	}
	
	@Override
	public void update(BpUser bpUser) {
		bpUserDao.updateNotNull(bpUser);
	}

//	@Override
//	public void delete(String ids) {
//		List<String> idList = Arrays.asList(ids.split(","));
//		bpUserDao.batchDelete(idList);
//	}
 	
}